/*-------------------------------------------------------------------------------------------------------------------------------------------
Program: SocialAcceptabilityGraphs_Round12.do
----------------------------------------------------------------------------------------------------------------------------------------*/
*version Stata/SE 17.0

clear all
set more off
macro drop _all

cd "/Volumes/GoogleDrive/My Drive/Documents/JMP/Work/Tables/tables_replication" 

use 				"merged_v0.31_replication.dta" , clear

encode session_id, gen(sess_id)
xtset sess_id 

datasignature report

forvalues i = 0(20)200 {

gen soc_acc2`i' = oth_acc2_`i'*100

}

forvalues i = 0(20)200 {

gen soc_acc1`i' = oth_acc1_`i'*100

}

reshape long soc_acc2 soc_acc1, i(id) j(amt_sent)

order soc_acc2 soc_acc1, before(oth_acc1_0)

reshape long soc_acc, i(id amt_sent) j(round)

recode round (1= 0) (2=1), gen(round_num)

gen acc_hat = .
gen acc_sd  = .


 bysort id round: egen x = sum(soc_acc)
 tab x
*********************************8
forvalues i = 1(1)6 {
forvalues j = 0(20)200{
xtreg			soc_acc 	round_num if treatment==`i' & amt_sent==`j', re  vce(cluster sess_id)
predict 		acc_hat`i'_`j'     if treatment==`i' & amt_sent==`j', xb
predict 		acc_sd`i'_`j' 	   if treatment==`i' & amt_sent==`j', stdp

replace acc_hat = acc_hat`i'_`j' if treatment==`i' & amt_sent==`j'
replace acc_sd  = acc_sd`i'_`j'  if treatment==`i' & amt_sent==`j'
drop  acc_hat`i'_`j' acc_sd`i'_`j'
}
}
/*Generating the confidence intervals*/
gen 	lo_acc = acc_hat-1.96*acc_sd	
gen 	hi_acc = acc_hat+1.96*acc_sd

drop round_num

collapse mean_soc_acc= soc_acc mean_lo_acc = lo_acc mean_hi_acc = hi_acc, by(amt_sent treatment round)


cd "Figure3_SocialAcceptabilityGraphs_Round12_v2"




graph twoway (line mean_soc_acc amt_sent if treatment==1 & round == 1) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==1 & round == 1) ///
			 (line mean_soc_acc amt_sent if treatment==1 & round == 2) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==1 & round == 2), ///
				ysc(range(0 100)) /// 
				ylabel(0(20)100, labsize(small)) xlabel(0(20)200, labsize(small))  xtitle("Amount shared with a low-caste participant", size(small)) ///
				ytitle("% of high-caste participants believing" "the amount shared is socially acceptable", size(small) margin(medium)) scheme(s2manual) legend(order (1 "Round 1" 3 "Round 2")) legend(size(small)) ///
				subtitle("Info 40 & No Rule in Round 2", size(medsmall)) 
				
graph save T1_norm, replace

graph twoway (line mean_soc_acc amt_sent if treatment==2 & round == 1) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==2 & round == 1) ///
			 (line mean_soc_acc amt_sent if treatment==2 & round == 2) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==2 & round == 2), ///
				ysc(range(0 100)) /// 
				ylabel(0(20)100, labsize(small)) xlabel(0(20)200, labsize(small))  xtitle("Amount shared with a low-caste participant", size(small)) ///
				ytitle("% of high-caste participants believing" "the amount shared is socially acceptable", size(small) margin(medium)) scheme(s2manual) legend(order (1 "Round 1" 3 "Round 2")) legend(size(small)) ///
				subtitle("Info 40 & Rule 60 in Round 2", size(medsmall)) 
graph save T2_norm, replace

graph twoway (line mean_soc_acc amt_sent if treatment==3 & round == 1) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==3 & round == 1) ///
			 (line mean_soc_acc amt_sent if treatment==3 & round == 2) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==3 & round == 2), ///
				ysc(range(0 100)) /// 
				ylabel(0(20)100, labsize(small)) xlabel(0(20)200, labsize(small))  xtitle("Amount shared with a low-caste participant", size(small)) ///
				ytitle("% of high-caste participants believing" "the amount shared is socially acceptable", size(small) margin(medium)) scheme(s2manual) legend(order (1 "Round 1" 3 "Round 2")) legend(size(small)) ///
                subtitle("Info 40 & Rule 100 in Round 2", size(medsmall)) 
graph save T3_norm, replace

graph twoway (line mean_soc_acc amt_sent if treatment==4 & round == 1) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==4 & round == 1) ///
			 (line mean_soc_acc amt_sent if treatment==4 & round == 2) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==4 & round == 2), ///
				ysc(range(0 100)) /// 
				ylabel(0(20)100, labsize(small)) xlabel(0(20)200, labsize(small))  xtitle("Amount shared with a low-caste participant", size(small)) ///
				ytitle("% of high-caste participants believing" "the amount shared is socially acceptable", size(small) margin(medium)) scheme(s2manual) legend(order (1 "Round 1" 3 "Round 2")) legend(size(small)) ///
				subtitle("Info 60 & No Rule in Round 2", size(medsmall)) 
graph save T4_norm, replace

graph twoway (line mean_soc_acc amt_sent if treatment==5 & round == 1) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==5 & round == 1) ///
			 (line mean_soc_acc amt_sent if treatment==5 & round == 2) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==5 & round == 2), ///
				ysc(range(0 100)) /// 
				ylabel(0(20)100, labsize(small)) xlabel(0(20)200, labsize(small))  xtitle("Amount shared with a low-caste participant", size(small)) ///
				ytitle("% of high-caste participants believing" "the amount shared is socially acceptable", size(small) margin(medium)) scheme(s2manual) legend(order (1 "Round 1" 3 "Round 2")) legend(size(small)) ///
				subtitle("Info 60 & Rule 60 in Round 2", size(medsmall)) 
graph save T5_norm, replace

graph twoway (line mean_soc_acc amt_sent if treatment==6 & round == 1) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==6 & round == 1) ///
			 (line mean_soc_acc amt_sent if treatment==6 & round == 2) ///
             (rcap mean_hi_acc mean_lo_acc amt_sent if treatment==6 & round == 2), ///
				ysc(range(0 100)) /// 
				ylabel(0(20)100, labsize(small)) xlabel(0(20)200, labsize(small))  xtitle("Amount shared with a low-caste participant", size(small)) ///
				ytitle("% of high-caste participants believing" "the amount shared is socially acceptable", size(small) margin(medium)) scheme(s2manual) legend(order (1 "Round 1" 3 "Round 2")) legend(size(small)) ///
				subtitle("Info 60 & Rule 100 in Round 2", size(medsmall)) 
graph save T6_norm, replace

gr combine 		T1_norm.gph 	T2_norm.gph 	T3_norm.gph, ///
				ycommon 		xcommon	cols(1)	ysize(11) xsize(6)	///
				title("Info 40") 
				
graph save "socacc12info40_v3.gph", replace


graph export socacc12info40_v3.pdf, replace 


gr combine 		T4_norm.gph T5_norm.gph T6_norm.gph, ///
				ycommon 		xcommon	cols(1)	ysize(11) xsize(6)	///
				title("Info 60") 
							
graph save "socacc12info60_v3.gph", replace

graph export socacc12info60_v3.pdf, replace 

gr combine		socacc12info40_v3.gph 	socacc12info60_v3.gph, cols(2) ysize(11) xsize(7) ///
				title("Effect of Rules on Social Acceptability") ///
				note("Estimates and CI are predicted using GLS specification with session level" ///
				"random effects and standard errors are clustered at the session level.", size(small)) 
graph save "socacc12_v3.gph", replace
graph export socacc12_v3.pdf, replace 


				
exit
